# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.shortcuts import render

# Create your views here.

from django.http import HttpResponse
from .models import Question, Choice, Users, _print_records
import time

import mongoengine
from mongoengine import connect
from mongoengine.document import Document
from mongoengine.fields import StringField, IntField
connect('xxbbj', host='localhost', port=27017)

class U(Document):
  uname = mongoengine.StringField(max_length=100)
  uid = mongoengine.StringField(max_length=256)
  age = mongoengine.IntField(max_length=100)

# def create_record(uname, uid, age):
#   user = U()
#   user.uname = uname
#   user.uid = uid
#   user.age = age
#   return user

def print_records():
  records = list(U.objects.all())
  # print('{} count:{}, records:'.format(User._meta['db_alias'], len(records)))
  # for rc in records:
    # print('    {}|{}|{}'.format(rc['uname'], rc['uid'], rc['age']))
    # print('+')

def index(request):
  print('=======================================')
  print(U)
  print(Users)
  print_records()
  # create_record('Ace', 'AX001', 10).save()
  _print_records()
  print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
  return HttpResponse("hello, world. You're at the polls index.")